TOOL.Category		= "Cosmos"
TOOL.Name			= "#Mass"
TOOL.Command		= nil
TOOL.ConfigName		= nil

TOOL.ClientConVar[ "mass" ] = "100";

if( CLIENT ) then
	
	language.Add( "Tool_cosmos_mass_name", "Mass" );
	language.Add( "Tool_cosmos_mass_desc", "Change something's mass." );
	language.Add( "Tool_cosmos_mass_0", "Left click on a prop to set its mass. Right click to copy mass." );
	
end

function TOOL:LeftClick( tr )
	
	if( !tr.Entity or !tr.Entity:IsValid() ) then return end
	
	if( CLIENT ) then return true end
	
	local phys = tr.Entity:GetPhysicsObject();
	
	if( !phys or !phys:IsValid() ) then return end
	
	phys:SetMass( math.Clamp( self:GetClientNumber( "mass" ), 0, 20000 ) );
	return true
	
end

function TOOL:RightClick( tr )
	
	if( !tr.Entity or !tr.Entity:IsValid() ) then return end
	
	if( CLIENT ) then return true end
	
	local phys = tr.Entity:GetPhysicsObject();
	
	if( !phys or !phys:IsValid() ) then return end
	
	local mass = phys:GetMass();
	RunConsoleCommand( "cosmos_mass_mass", tostring( math.Round( mass ) ) );
	
	return true;
	
end

function TOOL:Reload( tr )
	
	return true
	
end

function TOOL:BuildCPanel()
	
	local mass = vgui.Create( "DNumSlider" );
	mass:SetText( "Mass" );
	mass:SetMin( 1 );
	mass:SetMax( 10000 );
	mass:SetDecimals( 0 );
	mass:SetConVar( "cosmos_mass_mass" );
	self:AddItem( mass );
	
end
